package io.cici.cc.mybatis.lite.transaction;

import javax.sql.DataSource;
import java.sql.Connection;
import java.util.Properties;


public class TransactionFactoryImpl implements TransactionFactory {

    private boolean skipSetAutoCommitOnClose;

    @Override
    public void setProperties(Properties props) {
        if (props == null) {
            return;
        }
        String value = props.getProperty("skipSetAutoCommitOnClose");
        if (value != null) {
            skipSetAutoCommitOnClose = Boolean.parseBoolean(value);
        }
    }

    @Override
    public Transaction newTransaction(Connection conn) {
        return new TransactionImpl(conn);
    }

    @Override
    public Transaction newTransaction(DataSource ds, boolean autoCommit) {
        return new TransactionImpl(ds, autoCommit, skipSetAutoCommitOnClose);
    }
}
